package com.fesine.ssh.service.impl;

import com.fesine.ssh.dao.UserDao;
import com.fesine.ssh.model.User;
import com.fesine.ssh.service.UserService;
import com.fesine.ssh.util.ShopException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Fesine on 2016/2/20.
 */
@Service("userService")
public class UserServiceImpl implements UserService  {

    @Autowired
    private UserDao userDao;


    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public List<User> findAll(int offset, int pageSize) {
        return userDao.findAll(offset, pageSize);
    }

    @Override
    public List<User> findByEntity(User user) {
        return userDao.findByEntity(user);
    }

    @Override
    public List<User> findByEntity(User entity, int offset, int pageSize) {
        return userDao.findByEntity(entity, offset, pageSize);
    }


    @Override
    public String register(User entity) {
        return userDao.save(entity);
    }

    @Override
    public void modify(User entity) {
        userDao.update(entity);
    }

    @Override
    public void delete(String[] userIds) throws ShopException{
        for (String id : userIds) {
            userDao.deleteByUserId(id);
        }
    }

    public User findByUserId(String userId) {
       return userDao.findByUserId(userId);
    }

    @Override
    public boolean login(String username, String password) {
        return userDao.login(username, password);
    }

    @Override
    public boolean checkUsername(String username) {
        return userDao.checkUsername(username);
    }

}
